package com.mauroleon.promotail.service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.json.GsonHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import com.mauroleon.promotail.canonical.Promocion;
import com.mauroleon.promotail.canonical.Categoria;


public class PromotailServiceImpl implements PromotailService{
	
	
	@Override
	public ArrayList<Categoria> listarCategoria() {
		List<Categoria> categoria = null;
		String url = "http://192.168.1.33:8708/promotail-platform/resources/categorias";
		
		HttpHeaders requestHeaders = new HttpHeaders();
		requestHeaders.setAccept(Collections.singletonList(new MediaType("application","json")));
		HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);

		RestTemplate restTemplate = new RestTemplate();

		// Add the Gson message converter
		restTemplate.getMessageConverters().add(new GsonHttpMessageConverter());

		// Make the HTTP GET request, marshaling the response from JSON to an array of Events
		ResponseEntity<Categoria[]> responseEntity = restTemplate.exchange(url, HttpMethod.GET, requestEntity, Categoria[].class);
		Categoria[] categorias = responseEntity.getBody();
		System.out.println("Hola mundo" + categorias.length);
		categoria = Arrays.asList(categorias);
		return new  ArrayList<Categoria>(categoria);
	}

	@Override
	public ArrayList<Promocion> listarPromocionPorEstado() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ArrayList<Promocion> listarPromocionPorCategoria() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ArrayList<Promocion> listarPromocionPorDistrito() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ArrayList<Promocion> listarPromocionPorLocal() {
		// TODO Auto-generated method stub
		return null;
	}

}
